<div class="content-wrapper">
	<section class="content-header">
		<h1>功能列表</h1>
		<ol class="breadcrumb">
			<li><a href="/admin"><i class="fa fa-dashboard"></i> 首页</a></li>
			<li class="active">权限管理</li>
			<li class="active">功能列表</li>
		</ol>
	</section>
	<section class="content">
		<div class="box">
			<div class="box-header with-border">
				<form class="form-inline">
					<input type="hidden" name="function_id" id="function_id" value="{$functionInfo.id}" />
					<div class="form-group">
						<label for="name">功能名 </label> 
						<input type="text" class="form-control" id="name" name="name" placeholder="功能名" value="{$functionInfo.name}">
					</div>	
					<div class="form-group">
						<label for="path">URL </label> 
						<input type="text" class="form-control" id="path" name="path" placeholder="URL" value="{$functionInfo.path}">
					</div>
					<div class="form-group">
						<label for="group_id">功能组 </label> 
						<select name="group_id" id="group_id" class="form-control">
                         	<foreach name="functionGroupList" item="group">
                         		<option <if condition="$functionInfo['group_id'] eq $group['id']">selected</if> value="{$group.id}">{$group.name}</option>
                         	</foreach>
                         </select>
					</div>					
					<button type="button" class="btn btn-info" id="save-btn">{$functionInfo?'修改':'添加'}</button>&nbsp;
					<button type="button" class="btn btn-danger" onclick="window.location.href='/admin/auth/functionList'">取消</button>
				</form>
			</div>
			<div class="box-body">
				<table class="table table-bordered">
					<tbody>
						<tr>
							<th style="width: 40px">ID</th>
							<th>功能名</th>
							<th>URL</th>
							<th>功能组</th>
							<th style="width: 215px">操作</th>
						</tr>
						<foreach name="functionGroupList" item="functionGroup">
                         	<tr>
                         		<td colspan="5"><label style="width:250px;font-weight: bold;" class="position-relative">{$functionGroup.name}</label></td>
                         	</tr>
                         	<foreach name="functionGroup.functionList" item="function">
                         		<tr>
                         			<td>{$function.id}</td>
                         			<td>{$function.name}</td>
                         			<td><a target="_black" href="{$function.path}">{$function.path}</a></td>
                         			<td>{$functionGroup.name}</td>
                         			<td>
                         				<button class="btn btn-danger btn-xs" type="button" onclick="window.location.href='/admin/auth/functionList?id={$function.id}'">修改</button>&nbsp;                         				
                         			</td>
                         		</tr>
                         	</foreach>
                         </foreach>
					</tbody>
				</table>
			</div>			
		</div>
	</section>
</div>
<script type="text/javascript">
$(function(){
	$("#save-btn").click(function(){
		var id = $("#function_id").val();
		var name = $.trim($("#name").val());
		var path = $.trim($("#path").val());
		var group_id = $("#group_id").val();
		
		if(name == '') {
			ArtDialogHlp.showInfo('提示', '请填写功能名');
            return false;
        }
		
		if(path == '') {
			ArtDialogHlp.showInfo('提示', '请填写URL');
            return false;
        }
		
		$.post('/admin/auth/saveFunction', {id:id, name:name, path:path, group_id:group_id}, function(data){
			if(data.Code == 999) {
				ArtDialogHlp.showInfo('提示', '操作成功', function(){
					window.location.href = '/admin/auth/functionList';
				});
			} else {
				ArtDialogHlp.showInfo('提示', data.Msg);
			}
		}, 'json');
	});
});
</script>